package com.jredu.controller.server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jredu.entity.User;

@Controller
@RequestMapping("/user")
public class UserController {

	///user/delUser/1
	@RequestMapping("/delUser/{userId}")
	public String delUserById(
			@PathVariable("userId") Integer id){
		System.out.println("要删除的用户编号为："+id);
		return "users/user_add";
	}
	
	@RequestMapping("/doLogin")
	public String login(
			@RequestParam(value="at") String account,
			String pwd){
		System.out.println("用户名："+account);
		System.out.println("密码："+pwd);
		return "users/user_add";
	}
	
	@RequestMapping("/addUser")
	public String addUser(User user){
		System.out.println("用户名："+user.getAccount());
		System.out.println("密码："+user.getPwd());
		return "users/user_add";
	}
	
	@RequestMapping("/findUsers")
	public void findUsers(HttpServletResponse response) throws IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.write("就是这么简单！！！！");
		out.close();
	}
	
	@RequestMapping("/findUserById")
	public String findUsersById(@ModelAttribute("user") User user){
		System.out.println(user);
		return "users/user_add";
	}
}
